home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / programming / c / objective / examples / manx / viewfile_wrong.c < prev    next >
C/C++ Source or Header  |  1978-11-24  |  9KB  |  311 lines

  1. /*
  2. ** $Filename: viewfile_wrong.c $
  3. ** $Release : 1.0              $
  4. ** $Revision: 1.274            $
  5. ** $Date    : 21/10/92         $
  6. **
  7. **
  8. ** (C) Copyright 1992 Davide Massarenti
  9. **              All Rights Reserved
  10. **
  11. ** MANX 5.2: cc -ps -wdrunpo -so <name>.c
  12. **           ln -o <name> <name>.o -lOGTglue -lc16
  13. **
  14. */
  15.  
  16. #include <OGT/ObjectiveGadTools.h>
  17.  
  18. #define ARGS_TEMPLATE "FILE/K,FONT/K,SIZE/N"
  19. #define ARGS_FILE       (0)
  20. #define ARGS_FONT       (1)
  21. #define ARGS_SIZE       (2)
  22. #define ARGS_NUMOF      (3)
  23.  
  24. static LONG args[ ARGS_NUMOF ];
  25.  
  26. #define GADGETID_SHOWLIST  (1)
  27.  
  28. static char Class_AslReq  [] =   ASLREQ_OGT_CLASS;
  29. static char Class_Scroller[] = SCROLLER_OGT_CLASS;
  30. static char Class_Showlist[] = SHOWLIST_OGT_CLASS;
  31.  
  32. struct TextAttr   MyAttr = { NULL, 8 };
  33. struct TextFont  *MyFont;
  34.  
  35. APTR              VInfo;
  36. struct Window    *Win;
  37. Object          **Gads;
  38. struct RDArgs    *Ra;
  39.  
  40.  
  41. struct TagItem WindowDescTags[] =
  42. {
  43.    { OVI_GimmeZeroZero    , TRUE                                  },
  44.    { OVI_AdaptWidthToFont , TRUE                                  },
  45.    { OVI_AdaptHeightToFont, TRUE                                  },
  46.    { OGT_ScaleLeft        , OGT_FontRelative                      },
  47.    { OGT_ScaleTop         , OGT_FontRelative                      },
  48.    { OGT_ScaleWidth       , OGT_FontRelative                      },
  49.    { OGT_ScaleHeight      , OGT_FontRelative                      },
  50.    { OGT_DomainXscale     , ~0                                    },
  51.    { OGT_DomainYscale     , ~0                                    },
  52.    { WA_Title             , "ViewFile"                            },
  53.    { WA_Activate          , TRUE                                  },
  54.    { WA_SmartRefresh      , TRUE                                  },
  55.    { WA_NoCareRefresh     , TRUE                                  },
  56.    { WA_DepthGadget       , TRUE                                  },
  57.    { WA_SizeGadget        , TRUE                                  },
  58.    { WA_SizeBBottom       , TRUE                                  },
  59.    { WA_SizeBRight        , TRUE                                  },
  60.    { WA_DragBar           , TRUE                                  },
  61.    { WA_Left              , 400                                   },
  62.    { WA_Top               , 150                                   },
  63.    { WA_InnerWidth        , 306                                   },
  64.    { WA_InnerHeight       , 120                                   },
  65.    { WA_MaxWidth          , -1                                    },
  66.    { WA_MaxHeight         , -1                                    },
  67.    { WA_IDCMP             , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE },
  68.    { WA_CloseGadget       , TRUE                                  },
  69.    { TAG_DONE                                                     }
  70. };
  71.  
  72.  
  73. struct TagItem Object1Desc[] = /* ASLREQ_OGT_CLASS */
  74. {
  75.    { OGT_SetDimReference, OGT_X_Dim_Relative },
  76.    { OGT_SetPosHandle   , OGT_Y_Bottom       },
  77.    { GA_RelBottom       , 0                  },
  78.    { GA_Height          , 14                 },
  79.  
  80.    { GA_Text            , "_F"               },
  81.    { OGT_TextPlacement  , OGT_Text_HIDE      },
  82.  
  83.    { OGTAR_Type         , ASL_FileRequest    },
  84.    { OGTAR_ShowSelected , TRUE               },
  85.    { TAG_DONE                                }
  86. };
  87.  
  88. struct TagItem Object1Post[] =
  89. {
  90.    { OGTAR_FullFileName },
  91.    { TAG_DONE           }
  92. };
  93.  
  94.  
  95. struct TagItem Object2Desc[] = /* SCROLLER_OGT_CLASS */
  96. {
  97.    { GA_Immediate       , TRUE                                    },
  98.    { GA_FollowMouse     , TRUE                                    },
  99.    { GA_RelVerify       , TRUE                                    },
  100.    { ICA_TARGET         , NULL                                    },
  101.  
  102.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  103.    { GA_RightBorder     , TRUE                                    },
  104.  
  105.    { PGA_Freedom        , FREEVERT                                },
  106.    { TAG_DONE                                                     }
  107. };
  108.  
  109.  
  110. struct TagItem Object3Desc[] = /* SCROLLER_OGT_CLASS */
  111. {
  112.    { GA_Immediate       , TRUE                                    },
  113.    { GA_FollowMouse     , TRUE                                    },
  114.    { GA_RelVerify       , TRUE                                    },
  115.    { ICA_TARGET         , NULL                                    },
  116.  
  117.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  118.    { GA_BottomBorder    , TRUE                                    },
  119.  
  120.    { PGA_Freedom        , FREEHORIZ                               },
  121.    { TAG_DONE                                                     }
  122. };
  123.  
  124.  
  125. struct TagItem Object4Desc[] = /* SHOWLIST_OGT_CLASS */
  126. {
  127.    { GA_ID              , GADGETID_SHOWLIST                     },
  128.    { OGT_AppGadget      , TRUE                                  },
  129.    { GA_Immediate       , TRUE                                  },
  130.    { GA_FollowMouse     , TRUE                                  },
  131.    { GA_RelVerify       , TRUE                                  },
  132.    { ICA_TARGET         , NULL                                  },
  133.  
  134.    { OGT_SetDimReference, OGT_X_Dim_Relative|OGT_Y_Dim_Relative },
  135.    { GA_Height          , -14                                   },
  136.  
  137.    { OGTSL_UseNumPad    , TRUE                                  },
  138.    { TAG_DONE                                                   }
  139. };
  140.  
  141. struct OGT_ObjectSettings ListOfObjects[] =
  142. {
  143.    { Class_AslReq  , Object1Desc, Object1Post, OGT_NOOBJECT, OGT_NOOBJECT },
  144.    { Class_Scroller, Object2Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  145.    { Class_Scroller, Object3Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  146.    { Class_Showlist, Object4Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  147.    { NULL                                                                 },
  148. };
  149.  
  150.  
  151.  
  152. struct TagItem Obj2toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  153. {
  154.    { PGA_Top , OGTSL_VertPos },
  155.    { TAG_DONE                }
  156. };
  157.  
  158.  
  159. struct TagItem Obj3toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  160. {
  161.    { PGA_Top , OGTSL_HoriPos },
  162.    { TAG_DONE                }
  163. };
  164.  
  165.  
  166. struct TagItem Obj4toObj2[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  167. {
  168.    { OGTSL_VertPos    , PGA_Top     },
  169.    { OGTSL_VertTotal  , PGA_Total   },
  170.    { OGTSL_VertVisible, PGA_Visible },
  171.    { TAG_DONE                       }
  172. };
  173.  
  174. Tag Obj4toObj2Filter[] =
  175. {
  176.    OGTSL_VertPos    ,
  177.    OGTSL_VertTotal  ,
  178.    OGTSL_VertVisible,
  179.    TAG_DONE
  180. };
  181.  
  182.  
  183. struct TagItem Obj4toObj3[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  184. {
  185.    { OGTSL_HoriPos    , PGA_Top     },
  186.    { OGTSL_HoriTotal  , PGA_Total   },
  187.    { OGTSL_HoriVisible, PGA_Visible },
  188.    { TAG_DONE                       }
  189. };
  190.  
  191. Tag Obj4toObj3Filter[] =
  192. {
  193.    OGTSL_HoriPos    ,
  194.    OGTSL_HoriTotal  ,
  195.    OGTSL_HoriVisible,
  196.    TAG_DONE
  197. };
  198.  
  199.  
  200. struct TagItem Obj4toObj1[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  201. {
  202.    { OGT_DroppedIcon, OGTAR_FullFileName },
  203.    { TAG_DONE                            }
  204. };
  205.  
  206. Tag Obj4toObj1Filter[] =
  207. {
  208.    OGT_DroppedIcon,
  209.    TAG_DONE
  210. };
  211.  
  212.  
  213. struct TagItem Obj1toObj4[] =    /* ASLREQ_OGT_CLASS to SHOWLIST_OGT_CLASS */
  214. {
  215.    { OGTAR_FullFileName, OGTSL_FileToLoadByName },
  216.    { TAG_DONE                                   }
  217. };
  218.  
  219. Tag Obj1toObj4Filter[] =
  220. {
  221.    OGTAR_FullFileName,
  222.    TAG_DONE
  223. };
  224.  
  225.  
  226. struct OGT_ObjectLink ListOfLinks[] =
  227. {
  228.    { 3           , 1, Obj4toObj2, Obj4toObj2Filter },
  229.    { 3           , 2, Obj4toObj3, Obj4toObj3Filter },
  230.    { 1           , 3, Obj2toObj4                   },
  231.    { 2           , 3, Obj3toObj4                   },
  232.  
  233.    { 0           , 3, Obj1toObj4, Obj1toObj4Filter },
  234.    { 3           , 0, Obj4toObj1, Obj4toObj1Filter },
  235.  
  236.    { OGT_NOOBJECT                                  },
  237. };
  238.  
  239.  
  240. static int cleanup( char *str );
  241.  
  242. int main( void )
  243. {
  244.    if(!OpenOGT()) cleanup( "no objectivegadtools.library!\n" );
  245.  
  246.    if(!(Ra = ReadArgs( ARGS_TEMPLATE, args, NULL ))) return( cleanup( "Can't parse args\n" ) );
  247.  
  248.    if(args[ ARGS_FONT ]) MyAttr.ta_Name  =  (STRPTR )args[ ARGS_FONT ];
  249.    if(args[ ARGS_SIZE ]) MyAttr.ta_YSize = *(ULONG *)args[ ARGS_SIZE ];
  250.  
  251.    if(MyAttr.ta_Name)
  252.    {
  253.       if(!(MyFont = OpenDiskFont( &MyAttr ))) return( cleanup( "Can't open font!!\n" ) );
  254.    }
  255.  
  256.    while(1)
  257.    {
  258.       VInfo = OGT_GetVisualInfo( NULL, OGT_TextFont, (ULONG)MyFont         ,
  259.                                        TAG_MORE    , (ULONG)WindowDescTags );
  260.  
  261.       if(VInfo == NULL) return( cleanup( "Can't open my window.\n" ) );
  262.  
  263.       Object1Post[ 0 ].ti_Data = args[ ARGS_FILE ];
  264.  
  265.       if(!OGT_BuildObjects( VInfo, ListOfObjects, ListOfLinks, &Gads )) return( cleanup( "can't create objects" ) );
  266.  
  267.       Win = OGT_GetWindowPtr( VInfo );
  268.  
  269.       {
  270.          BOOL keeprunning = TRUE;
  271.  
  272.          while(keeprunning)
  273.          {
  274.             struct IntuiMessage *imsg;
  275.  
  276.             Wait( 1L << Win->UserPort->mp_SigBit );
  277.  
  278.             while(keeprunning && (imsg = OGT_GetMsg( VInfo )))
  279.             {
  280.                switch(imsg->Class)
  281.                {
  282.                   case IDCMP_CLOSEWINDOW:
  283.                      keeprunning = FALSE;
  284.                      break;
  285.                }
  286.  
  287.                OGT_ReplyMsg( imsg );
  288.             }
  289.          }
  290.       }
  291.  
  292.       break;
  293.    }
  294.  
  295.    return( cleanup( NULL ) );
  296. }
  297.  
  298. static int cleanup( char *str )
  299. {
  300.    if(str) Printf( "%s\n", str );
  301.  
  302.    if(Ra    ) FreeArgs          ( Ra     );
  303.    if(Gads  ) FreeVec           ( Gads   );
  304.    if(VInfo ) OGT_FreeVisualInfo( VInfo  );
  305.    if(MyFont) CloseFont         ( MyFont );
  306.  
  307.    CloseOGT();
  308.  
  309.    return( str ? 10 : 0 );
  310. }
  311.